<template>

  <a-comment>
    <a-avatar
      slot="avatar"
      src="/user.svg"
      alt="Han Solo"
    />
    <div slot="content">
      <a-form-item>
        <a-textarea :rows="4" :value="value" @change="handleChange"/>

        <a-button html-type="submit" type="primary" @click="handleSubmit">
          发表评论
        </a-button>
      </a-form-item>
    </div>
  </a-comment>

</template>
<script>
import { blogCommentAdd } from '@/api/modular/main/blogcomment/blogCommentManage'
// import VueEmoji from 'emoji-vue'

export default {
  components: {
  },
  data() {
    return {
      comments: [],
      submitting: false,
      value: ''
    }
  },
  props: [
    'content',
    'commentator',
    'pageNo',
    'pageSize'
  ],
  mounted() {
    if (this.commentator) {
      this.value = '@' + this.commentator + ' ; '
    }
    if (this.content.commentator) {
      this.value = '@' + this.content.commentator + ' ; '
    }
  },

  methods: {
    handleSubmit() {
      const that = this
      blogCommentAdd({
        parentId: this.content.parentId,
        blogId: this.content.blogId,
        commentator: '作者',
        commentBody: this.value
      }).then((res) => {
        if (res.code === 200 && res.success) {
          this.$message.success('发表成功！2秒后刷新')
          setTimeout(function () {
            that.$emit('parentFun')
          }, 2000)
        }
      })
    },
    handleChange(e) {
      this.value = e.target.value
    },
    onInput(event) {
      // event.data contains the value of the textarea
    },
    clearTextarea() {
      this.$refs.emoji.clear()
    }
  }

}

</script>
